//
//  ZBResultViewC.m
//  BaseRACDemo
//
//  Created by Angel_Yan on 2018/3/28.
//  Copyright © 2018年 庄波. All rights reserved.
//

#import "ZBResultViewC.h"
#import "ZBResultViewModel.h"
#import "ZBResultCellViewModel.h"
#import "ZBResultCell.h"
#import "ZBResultHeaderView.h"

@interface ZBResultViewC ()
@property (nonatomic, readwrite, strong) ZBResultViewModel *viewModel;

@end

@implementation ZBResultViewC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    /// 设置
    [self _setup];
    /// ③：注册cell
    self.
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.tableView.tableFooterView = [[UIView alloc] init];
    [self.tableView mh_registerNibCell:[ZBResultCell class]];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([ZBResultHeaderView class]) bundle:[NSBundle mainBundle]] forHeaderFooterViewReuseIdentifier:NSStringFromClass([ZBResultHeaderView class])];
    
}

- (void)bindViewModel {
    [super bindViewModel];
}


#pragma mark - Override
/// 配置tableView的区域
- (UIEdgeInsets)contentInset{
    return UIEdgeInsetsMake(SafeAreaTopHeight, 0, SafeAreaTabbarHeight, 0);
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 30;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    ZBResultHeaderView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:NSStringFromClass([ZBResultHeaderView class])];
    NSArray *arr = self.viewModel.dataSource[section];
    NSString *title = @"";
    if (arr.count) {
        ZBResultCellViewModel *item = [arr firstObject];
        title = item.itemModel.time;
    }
    view.labTitle.text = title;
    return view;
}



/// 返回自定义的cell
- (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath{
    return [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ZBResultCell class]) forIndexPath:indexPath];
   
}

/// 绑定数据
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object{
    ZBResultCell *cellResult = (ZBResultCell *)cell;
    [cellResult bindViewModel:object];
}


#pragma mark - 初始化
- (void)_setup{
    /// set up ...
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [self.viewModel.dataSource[indexPath.section][indexPath.row] cellHeight] ;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
